import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";

/**
 * index.js - render component
 * @date 2018/10/9
 */
import React from 'react';
import DrawDragField from "../Drag/DrawDragField";
import EmptyRender from "./EmptyRender";
import DynamicFormRender from "./DynamicFormRender";
import DynamicToolbarRender from "./DynamicToolbarRender";
import DynamicTableRender from "./DynamicTableRender"; // eslint-disable-next-line import/no-cycle

import DynamicTabsRender from "./DynamicTabsRender";

var ComponentRender = /*#__PURE__*/function (_React$Component) {
  _inherits(ComponentRender, _React$Component);

  var _super = _createSuper(ComponentRender);

  function ComponentRender(props) {
    var _this;

    _classCallCheck(this, ComponentRender);

    _this = _super.call(this, props);
    _this.wrapperFieldComponent = _this.wrapperFieldComponent.bind(_assertThisInitialized(_this));
    return _this;
  }

  _createClass(ComponentRender, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          component = _this$props.component,
          config = _this$props.config,
          onActiveField = _this$props.onActiveField,
          onAddField = _this$props.onAddField,
          onSwapField = _this$props.onSwapField,
          onRemoveField = _this$props.onRemoveField,
          onActiveComponent = _this$props.onActiveComponent,
          currentEditComponent = _this$props.currentEditComponent,
          currentEditField = _this$props.currentEditField,
          refRender = _this$props.refRender;
      var Render = EmptyRender;

      switch (component.templateType) {
        case 'DynamicForm':
          Render = DynamicFormRender;
          break;

        case 'DynamicToolbar':
          Render = DynamicToolbarRender;
          break;

        case 'DynamicTable':
          Render = DynamicTableRender;
          break;

        case 'DynamicTabs':
          Render = DynamicTabsRender;
          break;

        default:
          break;
      }

      return /*#__PURE__*/React.createElement(Render, Object.assign({}, config, {
        component: component,
        onActiveField: onActiveField,
        onSwapField: onSwapField,
        onAddField: onAddField,
        onRemoveField: onRemoveField,
        currentEditField: currentEditField,
        currentEditComponent: currentEditComponent,
        wrapperFieldComponent: this.wrapperFieldComponent,
        onActiveComponent: onActiveComponent,
        refRender: refRender
      }));
    }
  }, {
    key: "wrapperFieldComponent",
    value: function wrapperFieldComponent(fieldElement, field) {
      var _this$props2 = this.props,
          component = _this$props2.component,
          onSwapField = _this$props2.onSwapField,
          onAddField = _this$props2.onAddField,
          onActiveField = _this$props2.onActiveField,
          currentEditField = _this$props2.currentEditField;
      return /*#__PURE__*/React.createElement(DrawDragField, {
        pComponent: component,
        component: field,
        onSwapField: onSwapField,
        onAddField: onAddField,
        onActiveField: onActiveField,
        currentEditField: currentEditField
      }, fieldElement);
    }
  }]);

  return ComponentRender;
}(React.Component);

export { ComponentRender as default };